﻿$(function() {
	/**
	 * 加载生产线树结构
	 * */
    $("#switchbtn").click(function(){
    	var mePanel = $('#switchEquip');
   		mePanel.dialog('open');
   		$("#linetree").tree({
			url: basePath+"/lineConfig/generateTree.json",
			method: 'get',
			lines: true,
		});
    });
    
    /**
     * 显示生产线下的所有设备
     */
	$('#equip_data').datagrid({    
	    method: 'get',
	    striped : true,
		nowrap : true,
		rownumbers : true,
		fitColumns : true,
		border:false,
		scrollbarSize:1,
		singleSelect:true,
	    columns:[[
			{field:'equNo',align:'center','title':'设备编号',width:150},
			{field:'equName',align:'center','title':'设备名称',width:200},
			{field:'equType',align:'center','title':'设备类型',width:100},
			{field:'ratedPower',align:'center','title':'额定功率',width:150},
			{field:'supplier',align:'center','title':'生产厂家',width:150},
	    ]],
	    pagination : true,
  		pageList : [6,12,18],
  		pageNumber : 1,
		pageSize : 18,
  		pagePosition : 'bottom',
  		loadFilter:pagerFilter
	});
    
	
	$('#equipMold_data').datagrid({
		url: basePath+"/equMold/findByAll.json",
	    method: 'get',
	    striped : true,
		nowrap : true,
		rownumbers : true,
		fitColumns : true,
		singleSelect:true,
		border:false,
		scrollbarSize:1,
//		title:'设备类型',
//		queryParams:{lineId:null},
	    columns:[[
            {field:'equType',align:'center','title':'设备类型',width:200},
			{field:'equFormat',align:'center','title':'设备型号',width:200},
			{field:'ratedPower',align:'center','title':'额定功率',width:100},
			{field:'supplier',align:'center','title':'生产厂家',width:150},
			{field:'life',align:'center','title':'使用寿命',width:150}
	    ]],
	    pagination : true,
  		pageList : [5,10],
  		pageNumber : 1,
		pageSize : 10,
  		pagePosition : 'bottom',
	});
});

function pagerFilter(data){
	if (typeof data.length == 'number' && typeof data.splice == 'function'){	// is array
		data = {
			total: data.length,
			rows: data
		};
	}
	var dg = $(this);
	var opts = dg.datagrid('options');
	var pager = dg.datagrid('getPager');
	pager.pagination({
		onSelectPage:function(pageNum, pageSize){
			opts.pageNumber = pageNum;
			opts.pageSize = pageSize;
			pager.pagination('refresh',{
				pageNumber:pageNum,
				pageSize:pageSize
			});
			dg.datagrid('loadData',data);
		}
	});
	if (!data.originalRows){
		data.originalRows = (data.rows);
	}
	var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
	var end = start + parseInt(opts.pageSize);
	data.rows = (data.originalRows.slice(start, end));
	return data;
}